﻿using CommunityToolkit.Mvvm.ComponentModel;

namespace TotalApplication.Core
{
    public partial class ChatMessageListImageItemViewModel : BaseViewModel
    {
        #region Private Properties

        private string? _thumbnailUrl;

        #endregion

        #region Public properties

        [ObservableProperty]
        private string? _title;

        [ObservableProperty]
        private string? _filName;

        [ObservableProperty]
        private string? _localFilePath;

        [ObservableProperty]
        private long _fileSize;

        /// <summary>
        /// Indicates if an image has loaded
        /// </summary>
        public bool ImageLoaded => LocalFilePath != null;

        /// <summary>
        /// The thumbna URL of this attachment
        /// </summary>
        public string ThumbnailUrl
        {
            get => _thumbnailUrl ?? string.Empty;
            set
            {
                if(value == _thumbnailUrl) return;

                _thumbnailUrl = value;

                // TODO: Download Image From Website
                //       Save file to local storage/cache
                //       Set LocalFilePath Value
                //       
                //       For now, just set the file path directly
                Task.Delay(2000).ContinueWith(t => 
                { 
                    LocalFilePath = "/assets/img/example.png";
                    OnPropertyChanged(nameof(ImageLoaded));
                });
            }
        }

        #endregion

        #region Constructor

        public ChatMessageListImageItemViewModel()
        {
        }

        #endregion

    }
}
